﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StudyCode.ORM.Entities;

namespace StudyCode.ORM.Repository
{
    public class BookRepository:Repository<Book>
    {
        public override Book Get(long id)
        {
            //var book= base.Get(id);
            //var autorhRepository = new Repository<Author>();
            //book.Author = autorhRepository.Get(book.AuthorId);
            //return book;
            var entity = new Book()
            {
                Id = id,
            };
            string sqlStr = entity.EntityToSqlFromPrimaryKey();
            using (var sqlDataReader = SqlHelper.ExecuteReader(SqlHelper.GetConnection(), CommandType.Text, sqlStr))
            {

                //判断是否刻度，并且在使用数据前一定要运行才能读取
                if (!sqlDataReader.Read())
                    return null;
              
                entity.SqlToEntity(sqlDataReader);
                return entity;
            }
        }
    }
}
